<?php
namespace App\Http\Controllers\Api;

use App\Http\Resources\Api\NoticeResource;
use App\Models\Notice;

class NoticeController extends Controller
{
    public function index()
    {
        $notices = Notice::where(['tenant_id' => $this->tenant->id, 'is_enable' => true])
            ->orderByDesc('sort')
            ->get();
        return api()->success(NoticeResource::collection($notices));
    }

    public function getAllInOne()
    {
        $notice_text = Notice::where(['tenant_id' => $this->tenant->id, 'is_enable' => true])
            ->orderByDesc('sort')
            ->pluck('content')
            ->implode('  ');
        $notice_config = config("{$this->tenant->admin_prefix}.custom.group_course_order.weapp.notice");
        $return = [
            'notice_text' => $notice_text,
            'notice_config' => $notice_config,
        ];
        return api()->success($return);
    }
}
